package ch.zbw.sysVentory;

import java.awt.*;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import ch.zbw.sysVentory.daten.ComputerTyp;
import ch.zbw.sysVentory.daten.Speicher;

public class Gui {
    
    private JFrame main;
    private JTextField textUID = new JTextField();
    private JTextField textServerAdresse = new JTextField();
    private JLabel labelUID = new JLabel("UID");
    private JLabel labelZiel = new JLabel("Server Adresse");
    private JLabel labelTyp = new JLabel("Computer Typ");
    private JButton buttonSenden = new JButton("Senden");
    private JButton buttonSpeichern = new JButton("Speichern");
    private Speicher sp;
    
    private JPanel panel1 = new JPanel(new GridLayout(4,1));
    private JPanel panelUid = new JPanel(new GridLayout(1,2,5,5));
    private JPanel panelZiel = new JPanel(new GridLayout(1,2,5,5));
    private JPanel panelTyp = new JPanel(new GridLayout(1,2,5,5));
    private JPanel panel2 = new JPanel(new FlowLayout());   
    
    private JComboBox<ComputerTyp> comboComputerTyp= new JComboBox<ComputerTyp>();
    
    private ActionListener al;
    
    
    private int guiGroesseX = 300;
    private int guiGroesseY = 160;
    

    
    public Gui(Speicher sp, ActionListener al) {
	this.sp = sp;
	this.al = al;

	main = new JFrame("sysVetory");
	main.setSize(guiGroesseX, guiGroesseY);
	main.setResizable(false);
	main.setLayout(new GridLayout(1,1));
	main.add(panel1);
	panelUid.add(labelUID);
	panelUid.add(textUID);
	panelZiel.add(labelZiel);
	panelZiel.add(textServerAdresse);
	panelTyp.add(labelTyp);
	panelTyp.add(comboComputerTyp);
	panel1.add(panelUid);
	panel1.add(panelZiel);
	panel1.add(panelTyp);
	panel2.add(buttonSpeichern);
	panel2.add(buttonSenden);
	
	panel1.add(panel2);

	buttonSenden.addActionListener(al);
	buttonSpeichern.addActionListener(al);
	
	comboComputerTyp.addItem(ComputerTyp.DESKTOP);
	comboComputerTyp.addItem(ComputerTyp.NOTEBOOK);
	comboComputerTyp.addItem(ComputerTyp.NETBOOK);
	comboComputerTyp.addItem(ComputerTyp.SERVER);
	
	textServerAdresse.setText(sp.getZieladresse());
	textUID.setText(sp.getUid());
	comboComputerTyp.setSelectedItem(sp.getComputertyp());

	main.setVisible(true);
	
    }
    
    public void speicherVorbereitung(){
	sp.setUid(textUID.getText());
	sp.setZieladresse(textServerAdresse.getText());
	sp.setComputertyp((ComputerTyp)comboComputerTyp.getSelectedItem());
    }
}
